<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function flower(flowerbed, n) {
            let count = 0
            for (var i = 0; i < flowerbed.length; i++) {
                if(flowerbed.length===1&&flowerbed[0]===0){
                    return true
                }
                if (flowerbed[i] === 0) {
                    if (flowerbed[i - 1] === 0 && flowerbed[i + 1] === 0) {
                        flowerbed[i] = 1
                        count++
                    } else if(i===0 && flowerbed[i + 1] === 0){
                        flowerbed[i] = 1
                        count++
                   }else if(i===flowerbed.length-1 && flowerbed[i -1] === 0){
                        flowerbed[i] = 1
                        count++
                   }
                }
            }
            return count >= n ? true : false
        }
        console.log(flower([0], 1))
    </script>
</body>

</html>